package interview.huawei.myself.online2;

import java.util.ArrayDeque;
import java.util.Iterator;

/**
 * @Author CandyWall
 * @Date 2022/3/17--19:35
 * @Description
 */
public class Main {
    private int maxLength;
    private int length(String[] strs) {
        getLength(strs, 0, new ArrayDeque<String>());

        return maxLength;
    }

    private void getLength(String[] strs, int index, ArrayDeque<String> combination) {
        if (combination.size() == 2) {
            // 求两个字符串是否有相同元素
            Iterator<String> ite = combination.iterator();
            String str1 = ite.next();
            String str2 = ite.next();
            boolean flag = false;
            for (int i = 0; i < str1.length(); i++) {
                for (int j = 0; j < str2.length(); j++) {
                    if (str1.charAt(i) == str2.charAt(j)) {
                        flag = true;
                        break;
                    }
                }
            }
            // 如果没有相同元素，就计算长度乘积
            if (!flag) {
                maxLength = Math.max(maxLength, str1.length() * str2.length());
            }

            return;
        }

        for (int i = index; i < strs.length; i++) {
            combination.addLast(strs[i]);
            getLength(strs, i + 1, combination);
            combination.removeLast();
        }
    }

    public static void main(String[] args) {
        System.out.println(new Main().length(new String[]{"abcd", "efgh", "abc", "ijklm"}));
    }
}
